<template>
  <view>
    <view class="home-top">
      <u-swiper :list="swiperUrlList" height="168" @click="swiperDetail"></u-swiper>
    </view>

    <view class="businessWrapper">
      <short-rent></short-rent>
      <guide-view></guide-view>
      <view v-if="false" class="intoGroup" @click.stop="goGroup">
        <image src="https://qykh.shopec.com.cn/image-server/dz/home_intoGroup.png" mode=""></image>
      </view>
      <recommendCar></recommendCar>
    </view>
    <!-- 底部导航 -->
    <HomeTabbar :tab="0"></HomeTabbar>
  </view>
</template>

<script>
import HomeTabbar from '@/components/tabbar/tabbar'
import shortRent from '@/components/home/shortRent/shortRent.vue'
import guideView from '@/components/home/guide/guide.vue'
import recommendCar from '@/components/home/hotCar/recommendCar.vue'
import {
  tenantBusiness,
  homeGraphicList
} from '@/api/home-api.js'
import settings from '@/settings.js'

export default {
  components: {
    HomeTabbar,
    shortRent,
    guideView,
    recommendCar
  },
  data() {
    return {
      swiperDataList: [],
      swiperUrlList: []

    }
  },

  onReady() {
    // this.$store.dispatch('order/getOrderTime');
  },
  computed: {
    businessNo() {
      return this.$store.state.order.businessNo;
    }
  },
  onLoad(op) {

    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage']
    })

    if (op && op.scene) {
      let scene = op && op.scene.split('_');
      let memberNo = scene[0]; // memberNo
      console.log(memberNo)
      if (memberNo) {
        // 存入分享上级
        this.$store.commit('user/saveinviterId', memberNo);
      }
    }
    this.getTenantBusiness();
    this.getHomeGraphicList();
  },
  methods: {
    //获取业务信息
    getTenantBusiness() {
      tenantBusiness(this.$store.state.user.tenantId).then(res => {
        this.tabs = res.data;
        let defaultBusinessNo = res.data[0].busId;
        this.$store.commit('order/saveBusinessNo', defaultBusinessNo);
      })
    },
    // 获取首页banner
    getHomeGraphicList() {
      homeGraphicList(this.$store.state.user.tenantId).then(res => {
        if (res.code == 200) {
          this.swiperDataList = res.data;
          res.data.forEach(item => {
            this.swiperUrlList.push(settings.baseImageUrl + item.graphicUrl);
          })
        }
      })
    },
    // 点击轮播图
    swiperDetail(index) {
      let graphicObj = this.swiperDataList[index];
      let graphicId = graphicObj.graphicId;

      if (graphicObj.jumpType === 2) {
        uni.navigateToMiniProgram({
          appId: graphicObj.appid, // 跳转到其他小程序的AppId
          path: graphicObj.path // 跳转到其他小程序的页面路径
        });
      } else if (graphicObj.jumpType === 3) {
        uni.navigateTo({
          url: graphicObj.path
        })
      } else if (graphicObj.jumpType === 4) {
        uni.navigateTo({
          url: '/pages/guide/base_webview?webUrl='+ encodeURIComponent(graphicObj.path)
        })
      }else {
        uni.navigateTo({
          url: '/pages/guide/swiperDetail?graphicId=' + graphicId
        })
      }


    },




    // 进群福利
    goGroup() {
      uni.navigateTo({
        url: '/pages/guide/guide?type=15'
      })
    }

  }
}
</script>

<style lang="scss" scoped>
.home-top {
  width: 100%;
  height: 336rpx;
}

.businessWrapper {
  margin: -50rpx 20rpx 20rpx;

  .intoGroup {
    margin-top: 16rpx;
    width: 710rpx;
    height: 170rpx;

    image {
      width: 710rpx;
      height: 170rpx;
    }
  }
}
</style>
